<?php

namespace App\Admin\Controllers;

use App\Models\CardsModel;
use Illuminate\Http\Request;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Facades\DB;
use think\model\concern\TimeStamp;

class CardsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'CardsModel';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CardsModel());
        $grid->column('id', __('Id'));
        $grid->column('account', __('卡劵号'));
        $grid->column('password', __('卡密'));
        $grid->column('p_id', __('商品'))->display(function ($product){
            $product=$this->product;
            return $product->p_name;
        });
        $grid->column('status', __('状态'))->using(['1'=>'未使用','2'=>'已使用']);
        $grid->column('created_at', __('生成时间'));
        $grid->column('expiration_time', __('过期时间'))->display(function ($expiration_time){
            return date("Y--m-d H:i:s",$expiration_time);
        });
        $grid->disableCreateButton();
        $grid->disableExport();
        //$grid->disableColumnSelector();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CardsModel::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('account', __('Account'));
        $show->field('password', __('Password'));
        $show->column('p_id', __('商品'));
        $show->field('status', __('Status'));
        $show->field('created_at', __('Created at'));
        $show->field('expiration_time', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
}
